#include "LED.h"

const string LED::ANY_STR   = "ANY";
const string LED::RED_STR   = "RED";
const string LED::GREEN_STR = "GREEN";
const string LED::BLUE_STR  = "BLUE";

LED::LED(int pt)
{
    if(pt < 0 || pt > 3)
    {
        pt = LED::ANY;
    }
    port = pt;
    isOn = false;
	setLED(isOn);
}

void LED::setLED(bool isOn)
{
    if(port == GREEN || port == RED || port == BLUE)
    {
        send((unsigned char)(port*16+isOn));
        this->isOn = isOn;
    }
}
bool LED::getIsOn() {
    return isOn;
}
int LED::getColor()
{
    return port;
}

int LED::colorStringToInt(string s)
{
    for(int i = 0; i < s.size(); i++)
    {
        s[i] = toupper(s[i]);
    }
    if(s == RED_STR)
    {
        return LED::RED;
    }
    if(s == GREEN_STR)
    {
        return LED::GREEN;
    }
    if(s == BLUE_STR)
    {
        return LED::BLUE;
    }
    return LED::ANY;
}

string LED::intToColorString(int color) {
    switch (color)
    {
        case LED::RED:
            return LED::RED_STR;
        case LED::GREEN:
            return LED::GREEN_STR;
        case LED::BLUE:
            return LED::BLUE_STR;
        default:
            return LED::ANY_STR;
    }
}
